'''
@Project ：my_python_project 
@File    ：1.二分法.py
@IDE     ：PyCharm 
@Author  ：xionglinhui
@Date    ：2024/8/26 上午8:23 
'''

# 方案二：二分法
nums=[-3,4,10,7,8,1,2,11,13,21,43,77,89]
nums = sorted(nums)

def binary_search(find_num,l):
    print(l)
    if len(l) == 0:
        print('找的值不存在')
        return

    mid_index = len(l) // 2
    print(f'中间值：{l[mid_index]}')

    if find_num > l[mid_index]:
        l = l[mid_index+1:]
        binary_search(find_num, l)
    elif find_num < l[mid_index]:
        l = l[0:mid_index]
        binary_search(find_num,l)

    else:
        print(f'找到了')

    return mid_index

binary_search(2,nums)
